<?php
	// Load the QCubed Development Framework
	require('../includes/prepend.inc.php');

	/**
	 * This is a quick-and-dirty draft QForm object to do Create, Edit, and Delete functionality
	 * of the TableUserProject class.  It uses the code-generated
	 * TableUserProjectMetaControl class, which has meta-methods to help with
	 * easily creating/defining controls to modify the fields of a TableUserProject columns.
	 *
	 * Any display customizations and presentation-tier logic can be implemented
	 * here by overriding existing or implementing new methods, properties and variables.
	 * 
	 * NOTE: This file is overwritten on any code regenerations.  If you want to make
	 * permanent changes, it is STRONGLY RECOMMENDED to move both table_user_project_edit.php AND
	 * table_user_project_edit.tpl.php out of this Form Drafts directory.
	 *
	 * @package My Application
	 * @subpackage Drafts
	 */
	class TableUserProjectEditForm extends QForm {
		// Local instance of the TableUserProjectMetaControl
		protected $mctTableUserProject;

		// Controls for TableUserProject's Data Fields
		protected $lblId;
		protected $txtCategoryId;
		protected $txtSubcategoryId;
		protected $txtUserName;
		protected $txtPassword;
		protected $txtFirstname;
		protected $txtLastname;
		protected $txtCompanyname;
		protected $txtMail;
		protected $txtMail2;
		protected $txtIp;
		protected $txtCountry;
		protected $txtCity;
		protected $txtAddress1;
		protected $txtAddress2;
		protected $txtPostalCode;
		protected $txtPhone;
		protected $txtFax;
		protected $calLoginDate;
		protected $calLogoutDate;
		protected $calTimeupDate;
		protected $txtUserType;
		protected $txtUserLevel;
		protected $txtBoothCount;
		protected $txtPortfolioCount;
		protected $txtPointBalance;
		protected $txtPointInTotal;
		protected $txtPointOutTotal;
		protected $txtPointChargedTotal;
		protected $txtLanguageId;
		protected $txtSendmailNews;
		protected $txtSendmailByKeywordInNewProject;
		protected $txtSendmailByNewBid;
		protected $txtKeyword;
		protected $txtRateAsBuyer;
		protected $txtRateAsProvider;
		protected $txtRateAsBuyer6month;
		protected $txtRateAsProvider6month;
		protected $txtAuthorized;
		protected $txtAuthorizationCode;
		protected $calAuthorizedDate;
		protected $txtActive;
		protected $txtSuspended;
		protected $txtAffiliatorId;
		protected $txtAffliatorCode;
		protected $txtFirstnameKana;
		protected $txtLastnameKana;
		protected $txtDepartment;

		// Other ListBoxes (if applicable) via Unique ReverseReferences and ManyToMany References

		// Other Controls
		protected $btnSave;
		protected $btnDelete;
		protected $btnCancel;

		// Create QForm Event Handlers as Needed

//		protected function Form_Exit() {}
//		protected function Form_Load() {}
//		protected function Form_PreRender() {}

		protected function Form_Run() {
			// Security check for ALLOW_REMOTE_ADMIN
			// To allow access REGARDLESS of ALLOW_REMOTE_ADMIN, simply remove the line below
			QApplication::CheckRemoteAdmin();
		}

		protected function Form_Create() {
			// Use the CreateFromPathInfo shortcut (this can also be done manually using the TableUserProjectMetaControl constructor)
			// MAKE SURE we specify "$this" as the MetaControl's (and thus all subsequent controls') parent
			$this->mctTableUserProject = TableUserProjectMetaControl::CreateFromPathInfo($this);

			// Call MetaControl's methods to create qcontrols based on TableUserProject's data fields
			$this->lblId = $this->mctTableUserProject->lblId_Create();
			$this->txtCategoryId = $this->mctTableUserProject->txtCategoryId_Create();
            $this->txtCategoryId->Required=false;
			$this->txtSubcategoryId = $this->mctTableUserProject->txtSubcategoryId_Create();
			$this->txtUserName = $this->mctTableUserProject->txtUserName_Create();
			$this->txtPassword = $this->mctTableUserProject->txtPassword_Create();
			$this->txtFirstname = $this->mctTableUserProject->txtFirstname_Create();
			$this->txtLastname = $this->mctTableUserProject->txtLastname_Create();
			$this->txtCompanyname = $this->mctTableUserProject->txtCompanyname_Create();
			$this->txtMail = $this->mctTableUserProject->txtMail_Create();
			$this->txtMail2 = $this->mctTableUserProject->txtMail2_Create();
			$this->txtIp = $this->mctTableUserProject->txtIp_Create();
			$this->txtCountry = $this->mctTableUserProject->txtCountry_Create();
			$this->txtCity = $this->mctTableUserProject->txtCity_Create();
			$this->txtAddress1 = $this->mctTableUserProject->txtAddress1_Create();
			$this->txtAddress2 = $this->mctTableUserProject->txtAddress2_Create();
			$this->txtPostalCode = $this->mctTableUserProject->txtPostalCode_Create();
			$this->txtPhone = $this->mctTableUserProject->txtPhone_Create();
			$this->txtFax = $this->mctTableUserProject->txtFax_Create();
			$this->calLoginDate = $this->mctTableUserProject->calLoginDate_Create();
			$this->calLogoutDate = $this->mctTableUserProject->calLogoutDate_Create();
			$this->calTimeupDate = $this->mctTableUserProject->calTimeupDate_Create();
			$this->txtUserType = $this->mctTableUserProject->txtUserType_Create();
			$this->txtUserLevel = $this->mctTableUserProject->txtUserLevel_Create();
			$this->txtBoothCount = $this->mctTableUserProject->txtBoothCount_Create();
			$this->txtPortfolioCount = $this->mctTableUserProject->txtPortfolioCount_Create();
			$this->txtPointBalance = $this->mctTableUserProject->txtPointBalance_Create();
			$this->txtPointInTotal = $this->mctTableUserProject->txtPointInTotal_Create();
			$this->txtPointOutTotal = $this->mctTableUserProject->txtPointOutTotal_Create();
			$this->txtPointChargedTotal = $this->mctTableUserProject->txtPointChargedTotal_Create();
			$this->txtLanguageId = $this->mctTableUserProject->txtLanguageId_Create();
			$this->txtSendmailNews = $this->mctTableUserProject->txtSendmailNews_Create();
			$this->txtSendmailByKeywordInNewProject = $this->mctTableUserProject->txtSendmailByKeywordInNewProject_Create();
			$this->txtSendmailByNewBid = $this->mctTableUserProject->txtSendmailByNewBid_Create();
			$this->txtKeyword = $this->mctTableUserProject->txtKeyword_Create();
			$this->txtRateAsBuyer = $this->mctTableUserProject->txtRateAsBuyer_Create();
			$this->txtRateAsProvider = $this->mctTableUserProject->txtRateAsProvider_Create();
			$this->txtRateAsBuyer6month = $this->mctTableUserProject->txtRateAsBuyer6month_Create();
			$this->txtRateAsProvider6month = $this->mctTableUserProject->txtRateAsProvider6month_Create();
			$this->txtAuthorized = $this->mctTableUserProject->txtAuthorized_Create();
			$this->txtAuthorizationCode = $this->mctTableUserProject->txtAuthorizationCode_Create();
			$this->calAuthorizedDate = $this->mctTableUserProject->calAuthorizedDate_Create();
			$this->txtActive = $this->mctTableUserProject->txtActive_Create();
			$this->txtSuspended = $this->mctTableUserProject->txtSuspended_Create();
			$this->txtAffiliatorId = $this->mctTableUserProject->txtAffiliatorId_Create();
			$this->txtAffliatorCode = $this->mctTableUserProject->txtAffliatorCode_Create();
			$this->txtFirstnameKana = $this->mctTableUserProject->txtFirstnameKana_Create();
			$this->txtLastnameKana = $this->mctTableUserProject->txtLastnameKana_Create();
			$this->txtDepartment = $this->mctTableUserProject->txtDepartment_Create();

			// Create Buttons and Actions on this Form
			$this->btnSave = new QButton($this);
			$this->btnSave->Text = QApplication::Translate('Save');
			$this->btnSave->AddAction(new QClickEvent(), new QAjaxAction('btnSave_Click'));
			$this->btnSave->CausesValidation = true;

			$this->btnCancel = new QButton($this);
			$this->btnCancel->Text = QApplication::Translate('Cancel');
			$this->btnCancel->AddAction(new QClickEvent(), new QAjaxAction('btnCancel_Click'));

			$this->btnDelete = new QButton($this);
			$this->btnDelete->Text = QApplication::Translate('Delete');
			$this->btnDelete->AddAction(new QClickEvent(), new QConfirmAction(QApplication::Translate('Are you SURE you want to DELETE this') . ' ' . QApplication::Translate('TableUserProject') . '?'));
			$this->btnDelete->AddAction(new QClickEvent(), new QAjaxAction('btnDelete_Click'));
			$this->btnDelete->Visible = $this->mctTableUserProject->EditMode;
		}

		/**
		 * This Form_Validate event handler allows you to specify any custom Form Validation rules.
		 * It will also Blink() on all invalid controls, as well as Focus() on the top-most invalid control.
		 */
		protected function Form_Validate() {
			// By default, we report that Custom Validations passed
			$blnToReturn = true;

			// Custom Validation Rules
			// TODO: Be sure to set $blnToReturn to false if any custom validation fails!

			$blnFocused = false;
			foreach ($this->GetErrorControls() as $objControl) {
				// Set Focus to the top-most invalid control
				if (!$blnFocused) {
					$objControl->Focus();
					$blnFocused = true;
				}

				// Blink on ALL invalid controls
				$objControl->Blink();
			}

			return $blnToReturn;
		}

		// Button Event Handlers

		protected function btnSave_Click($strFormId, $strControlId, $strParameter) {
			// Delegate "Save" processing to the TableUserProjectMetaControl
			$this->mctTableUserProject->SaveTableUserProject();
			$this->RedirectToListPage();
		}

		protected function btnDelete_Click($strFormId, $strControlId, $strParameter) {
			// Delegate "Delete" processing to the TableUserProjectMetaControl
			$this->mctTableUserProject->DeleteTableUserProject();
			$this->RedirectToListPage();
		}

		protected function btnCancel_Click($strFormId, $strControlId, $strParameter) {
			$this->RedirectToListPage();
		}

		// Other Methods

		protected function RedirectToListPage() {
			QApplication::Redirect(__VIRTUAL_DIRECTORY__ . __FORM_DRAFTS__ . '/table_user_project_list.php');
		}
	}

	// Go ahead and run this form object to render the page and its event handlers, implicitly using
	// table_user_project_edit.tpl.php as the included HTML template file
	TableUserProjectEditForm::Run('TableUserProjectEditForm');
?>